package com.mck.controller;

import com.mck.entity.Result;
import com.mck.entity.Subject;
import com.mck.service.SubjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Max
 * @Date 2025/3/10 下午5:28
 */
@RestController
@RequestMapping("/api/public/subject")
@Slf4j
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    /**
     * 获取科目列表
     */
    @GetMapping
    public Result getSubjectList() {
        log.info("获取科目列表");

        List<Subject> subjectList = subjectService.getSubjectList();
        return Result.success(subjectList);
    }

    /**
     * 通过id获取指定科目
     */
    @PostMapping("/specific")
    public Result getSubjectBySpecific(@RequestBody List<Integer> id) {
        // System.out.println(id);
        log.info("获取指定科目");

        List<Subject> subjectInfo = subjectService.getSubjectsByIds(id);
        return Result.success(subjectInfo);
    }

    /**
     * 添加科目
     */
    @PostMapping
    public Result addSubject(@RequestBody Subject subject) {
        log.info("添加科目");

        subjectService.addSubject(subject);
        return Result.success();
    }

    /**
     * 删除科目
     */
    @DeleteMapping
    public Result deleteSubject(@RequestBody Integer id) {
        log.info("删除科目");

        subjectService.deleteSubject(id);
        return Result.success();
    }
}
